var n;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.GameDataMgr = undefined;
var r;
var DataManager = require("AA_DataManager");
var EventManager = require("AA_EventManager");
var TipsManager = require("AA_TipsManager");
var CommonUtils = require("AA_CommonUtils");
var Const_Common = require("AA_Const_Common");
var EvenType = require("AA_EvenType");
var Excel = require("AA_Excel");
var GameBagData = require("AA_GameBagData");
!function (e) {
  e.level = "level";
  e.tiaozhanlevel = "tiaozhanlevel";
  e.gameBag = "gameBag";
}(r || (r = {}));
var g = function (e) {
  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    t._secret_key = "game";
    t._level = {
      1: {
        ispass: false,
        maxboshu: 0,
        nowboshu: 0,
        awardjilu: 0,
        citiaodata: null,
        level: 1,
        huanyipi: 0,
        allhave: 0,
        rolelevel: 0
      }
    };
    t._tiaozhanlevel = {
      1: {
        isjixu: false,
        ispass: false,
        maxboshu: 0,
        nowboshu: 0,
        level: 1,
        leijifen: 0,
        awardjilu: null
      }
    };
    t._gameBag = new GameBagData.GameBagData.BagSaveData();
    return t;
  }
  __extends(t, e);
  t.prototype.init = function (e) {
    undefined === e && (e = null);
    var t = this.getNowData(r.level, e);
    this._level = __assign(__assign({}, this._level), t);
    var o = this.getNowData(r.tiaozhanlevel, e);
    this._tiaozhanlevel = __assign(__assign({}, this._tiaozhanlevel), o);
    var n = this.getNowData(r.gameBag, e);
    this._gameBag = __assign(__assign({}, this._gameBag), n);
  };
  t.prototype.getNowData = function (e, t) {
    var o = null;
    if (t && (o = t[e])) {
      this.updateDataMap(e, o);
    } else {
      o = this._load(e);
    }
    return o;
  };
  t.prototype.resetData = function () {
    this._level = {
      1: {
        ispass: false,
        maxboshu: 0,
        nowboshu: 0,
        awardjilu: 0,
        citiaodata: null,
        level: 1,
        huanyipi: 0,
        allhave: 0,
        rolelevel: 0
      }
    };
    this._tiaozhanlevel = {
      1: {
        isjixu: false,
        ispass: false,
        maxboshu: 0,
        nowboshu: 0,
        level: 1,
        leijifen: 0,
        awardjilu: null
      }
    };
    this._gameBag = new GameBagData.GameBagData.BagSaveData();
  };
  t.prototype.nowLevelData = function (e) {
    return this._level[e];
  };
  t.prototype.getCiTiaoCount = function (e, t) {
    var o = this._level[e];
    var n = 0;
    if (o) {
      switch (t) {
        case 1:
          n = o.huanyipi;
          break;
        case 2:
          n = o.allhave;
      }
    } else {
      switch (t) {
        case 1:
          n = 10;
          break;
        case 2:
          n = 6;
      }
    }
    return n;
  };
  t.prototype.cleanTiaoZhanLevel = function (e) {
    this._tiaozhanlevel[e] = {
      isjixu: false,
      ispass: false,
      maxboshu: 0,
      nowboshu: 0,
      level: 1,
      leijifen: 0,
      awardjilu: null
    };
    this._save(r.tiaozhanlevel, this._tiaozhanlevel);
  };
  t.prototype.updateTiaoZhanFen = function (e, t) {
    var o = this._tiaozhanlevel[e];
    if (o) {
      var n = o.leijifen;
      n || (n = 0);
      n += t;
      o.leijifen = n;
      this._tiaozhanlevel[e] = o;
      this._save(r.tiaozhanlevel, this._tiaozhanlevel);
      EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Game_TiaoZhan_JiFen);
    }
  };
  t.prototype.getTiaoZhanFen = function (e) {
    var t = this._tiaozhanlevel[e];
    var o = 0;
    t && t.leijifen && (o = t.leijifen);
    return o;
  };
  t.prototype.updateTiaoZhanJiXu = function (e, t) {
    var o = this._tiaozhanlevel[e];
    if (o) {
      var n = o.isjixu;
      n = t;
      o.isjixu = n;
      this._tiaozhanlevel[e] = o;
      this._save(r.tiaozhanlevel, this._tiaozhanlevel);
    }
  };
  t.prototype.updateRoleLevel = function (e, t, o, n) {
    if (2 == n) {
      var i = this._level[e];
      if (i) {
        var a = i.rolelevel;
        a || (a = {});
        a.level = t;
        a.levelexper = o;
        i.rolelevel = a;
      }
      this._level[e] = i;
      this._save(r.level, this._level);
    }
  };
  t.prototype.getRoleLevel = function (e, t) {
    if (2 == t) {
      var o = this._level[e];
      if (o) {
        return o.rolelevel;
      } else {
        return null;
      }
    }
  };
  t.prototype.updateNowLevel = function (e, t, o, n) {
    if (2 == n) {
      var i = this._level[e];
      if (i) {
        i.huanyipi = t;
        i.allhave = o;
      }
      this._level[e] = i;
      this._save(r.level, this._level);
    }
  };
  t.prototype.unLockLevelPro = function (e) {
    var t = this._level[e];
    t = {
      ispass: false,
      nowboshu: 0,
      awardjilu: {},
      level: e
    };
    this._level[e] = t;
    this._save(r.level, this._level);
  };
  t.prototype.getJiXuGame = function () {
    var e = Object.keys(this._level);
    var t = null;
    for (var o = 0; o < e.length; o++) {
      var n = e[o];
      var i = this._level[n];
      var a = Excel.Excel.shuiguoguanqia(Number(n));
      if (i && i.citiaodata) {
        a.levelboshuid.length <= i.maxboshu && this.updateLevelPassState(Number(n), 2);
        a.levelboshuid.length > i.nowboshu && (t = i);
        break;
      }
    }
    return t;
  };
  t.prototype.getJiXuTiaoZhan = function () {
    return !!this._tiaozhanlevel[1].isjixu;
  };
  t.prototype.updateCiTiao = function (e, t) {
    var o = this._level[e];
    o && (o.citiaodata = t ? t.concat() : null);
    this._save(r.level, this._level);
  };
  t.prototype.getNowMaxLevel = function () {
    var e = [];
    var t = this._level;
    for (var o in t) t[o] && t[o].ispass && e.push(Number(o));
    if ((e = e.sort(function (e, t) {
      if (e > t) {
        return 1;
      } else {
        return -1;
      }
    })).length <= 0) {
      return 0;
    } else {
      return e[e.length - 1];
    }
  };
  t.prototype.updateLevelBoShu = function (e, t, o) {
    if (1 == o) {
      var n = this._tiaozhanlevel[e];
      var i = Excel.Excel.shuiguotiaozhan(e);
      if (n) {
        c = n.maxboshu;
        if (!c) {
          c = 0;
        }
        t > i.levelboshuid.length && (t = i.levelboshuid.length);
        t >= c && (n.maxboshu = t);
        n.nowboshu = t;
      }
      this._tiaozhanlevel[e] = n;
      if (!i.levelboshuid[t]) {
        this.updateLevelPassState(e, o);
        var a = "无尽关卡通关";
        CommonUtils.default.SendPoint(Const_Common.SendPointType.通关无尽关卡, a);
      }
      this._save(r.tiaozhanlevel, this._tiaozhanlevel);
    }
    var c;
    if (2 == o) {
      n = this._level[e];
      i = Excel.Excel.shuiguoguanqia(e);
      if (n) {
        c = n.maxboshu;
        if (!c) {
          c = 0;
        }
        t > i.levelboshuid.length && (t = i.levelboshuid.length);
        if (t >= c) {
          n.maxboshu = t;
          a = "章节" + e + "_" + t + "波";
          CommonUtils.default.SendPoint(Const_Common.SendPointType.普通关卡进度, a);
        }
        n.nowboshu = t;
      }
      this._level[e] = n;
      i.levelboshuid[t] || this.updateLevelPassState(e, o);
      this._save(r.level, this._level);
    }
  };
  t.prototype.updateLevelPassState = function (e, t) {
    var o;
    if (1 == t) {
      o = this._tiaozhanlevel[e];
      if (o) {
        o.ispass = true;
      }
      this._tiaozhanlevel[e] = o;
      this._save(r.tiaozhanlevel, this._tiaozhanlevel);
      EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Game_TIAOZHAN_PASS);
    }
    if (2 == t) {
      o = this._level[e];
      if (o) {
        o.ispass = true;
      }
      this._level[e] = o;
      this.unLockLevelPro(e + 1);
      this._save(r.level, this._level);
      EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Game_PASS);
    }
  };
  t.prototype.getNowLevelPassState = function (e, t) {
    var o;
    if (1 == t) {
      if (o = this._tiaozhanlevel[e]) {
        if (o.ispass) {
          return 1;
        } else {
          return 2;
        }
      } else {
        return -1;
      }
    } else if (2 == t) {
      if (o = this._level[e]) {
        if (o.ispass) {
          return 1;
        } else {
          return 2;
        }
      } else {
        return -1;
      }
    } else {
      return undefined;
    }
  };
  t.prototype.getNowLevelBoshuState = function (e, t) {
    var o;
    var n;
    if (1 == t) {
      if (o = this._tiaozhanlevel[e]) {
        n = o.nowboshu;
        if (!n) {
          n = 0;
        }
        return n;
      } else {
        return 0;
      }
    } else if (2 == t) {
      if (o = this._level[e]) {
        n = o.nowboshu;
        if (!n) {
          n = 0;
        }
        return n;
      } else {
        return 0;
      }
    } else {
      return undefined;
    }
  };
  t.prototype.getMaxLevelBoshuState = function (e, t) {
    var o;
    var n;
    if (1 == t) {
      if (o = this._tiaozhanlevel[e]) {
        n = o.maxboshu;
        if (!n) {
          n = 0;
        }
        return n;
      } else {
        return 0;
      }
    } else if (2 == t) {
      if (o = this._level[e]) {
        n = o.maxboshu;
        if (!n) {
          n = 0;
        }
        return n;
      } else {
        return 0;
      }
    } else {
      return undefined;
    }
  };
  t.prototype.unTiaoZhanAwardJiLu = function (e, t) {
    var o = this._tiaozhanlevel[e];
    var n = o.awardjilu;
    n || (n = {});
    n[t] = "isok";
    o.awardjilu = n;
    this._tiaozhanlevel[e] = o;
    EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Game_Update_TiaoZhan_Award);
    this._save(r.tiaozhanlevel, this._tiaozhanlevel);
  };
  t.prototype.getTiaoZhanAwardJilu = function (e, t) {
    var o = this._tiaozhanlevel[e].awardjilu;
    return !!o && o[t];
  };
  t.prototype.unLevelAwardJiLu = function (e, t) {
    var o = this._level[e];
    var n = o.awardjilu;
    n || (n = {});
    n[t] = "isok";
    o.awardjilu = n;
    this._level[e] = o;
    EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Game_Update_Level_Award);
    this._save(r.level, this._level);
  };
  t.prototype.getLevelAwardJilu = function (e, t) {
    var o = this._level[e].awardjilu;
    return !!o && o[t];
  };
  t.prototype.getLevelAwardHave = function (e) {
    var t = Excel.Excel.shuiguoguanqia(e);
    if (t) {
      var o = t.awardboshuid;
      var n = this.getMaxLevelBoshuState(e, 2);
      var i = false;
      for (var a = 0; a < o.length; a++) {
        var r = o[a];
        if (n >= r && !this.getLevelAwardJilu(e, r)) {
          i = true;
          break;
        }
      }
      return i;
    }
  };
  Object.defineProperty(t.prototype, "gameBag", {
    get: function () {
      return this._gameBag;
    },
    enumerable: false,
    configurable: true
  });
  t.prototype.ClearGameBagData = function () {
    this._gameBag = new GameBagData.GameBagData.BagSaveData();
    this.SaveGameBagData();
    EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Game_YinBiValue);
  };
  t.prototype.SaveGameBagData = function () {
    this._save(r.gameBag, this._gameBag);
  };
  Object.defineProperty(t.prototype, "sliderCoin", {
    get: function () {
      return this._gameBag.silverCoin || 0;
    },
    enumerable: false,
    configurable: true
  });
  t.prototype.AddSliderCoin = function (e) {
    Number.isNaN(e) || (this._gameBag.silverCoin += e);
    EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Game_YinBiValue);
    this.SaveGameBagData();
  };
  t.prototype.SubSliderCoin = function (e) {
    if (!Number.isNaN(e)) {
      if (this._gameBag.silverCoin < e) {
        TipsManager.TipMgr.showToast("银币不足");
        return false;
      }
      this._gameBag.silverCoin -= e;
    }
    EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Game_YinBiValue);
    this.SaveGameBagData();
    return true;
  };
  return t;
}(DataManager.default);
exports.GameDataMgr = g.getInstance();